//Borrowed Idea from Bruce Allen

//Analog pin 0 for reading in the analog voltage from any inout
//This variable is a constant because the pin will not change throughout execution of this code.
const int anPin = A0;

//variables needed to store values
long anVolt, digitalmeasurement, analogmeasurement;
int sum=0;//Create sum variable so it can be averaged
int avgrange=5;//Quantity of values to average (sample size)

void setup() {

  //This opens up a serial connection to shoot the results back to the PC console
  Serial.begin(9600);

}

void loop() {

  pinMode(anPin, INPUT);

  for(int i = 0; i < avgrange ; i++)
  {
    //Used to read in an analog voltage output supplied by measured device.
    //Scale factor is (Vcc/1024) per inch. A 5V supply yields ~4.9mV/unit
    anVolt = analogRead(anPin);
    sum += anVolt;
    delay(10);

  }  

  digitalmeasurement = sum/avgrange;
  analogmeasurement = digitalmeasurement * 0.0049;
  Serial.print(digitalmeasurement);
  Serial.print(" recorded digital measurement, ");
  Serial.print(analogmeasurement);
  Serial.print(" recorded analog measurement (V)");
  Serial.println();

  //reset sample total
  sum = 0;

  delay(50);

} 
